package com.yra.service.impl;

import com.yra.common.Constants;
import com.yra.common.ServiceResultEnum;
import com.yra.domain.MallUser;
import com.yra.mapper.MallUserMapper;
import com.yra.service.MallUserService;
import com.yra.util.BeanUtil;
import com.yra.util.MD5Util;
import com.yra.util.PageQueryUtil;
import com.yra.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @Author: yrq
 * @Date: Create in 11:13 2019/12/12
 */
@Service
public class MallUserServiceImpl implements MallUserService {
    @Autowired
    private MallUserMapper mallUserMapper;


    @Override
    public PageResult mallUserListPage(PageQueryUtil pageQueryUtil) {
        List<MallUser> mallUsers = mallUserMapper.queryMallUserList(pageQueryUtil);
        int total = mallUserMapper.queryTotalMallUsers(pageQueryUtil);
        PageResult pageResult = new PageResult(mallUsers, total, pageQueryUtil.getLimit(), pageQueryUtil.getPage());
        return pageResult;
    }

    @Override
    public Boolean updateLockStatusByIds(int lockStatus, int[] ids) {
        if (ids.length<0){
            return false;
        }
        return mallUserMapper.updateLockStatusByIds(lockStatus,ids)>0;
    }

    @Override
    public Boolean insertMallUser(Map<String, Object> params) {
        String password = (String) params.get("password");
        params.put("password",MD5Util.MD5Encode(password, "UTF-8"));
        return mallUserMapper.insertMallUser(params)>0;
    }

    @Override
    public Boolean login(String userName, String password) {
        MallUser mallUser = mallUserMapper.queryUserByuserName(userName);
        if (password.equals(mallUser.getPassword())){
            return true;
        }
        return false;
    }


}
